from django.shortcuts import render, redirect, get_object_or_404
from rest_framework.response import Response
from rest_framework.views import APIView

from apps.models import Theme, Column
from apps.tools.tools import theme_clear_data, column_clear_data

class ImageView(APIView):
    def get(self,request):
        theme_data = Theme.objects.all().values()
        data = theme_clear_data(theme_data)
        return render(request,'index.html',data)


class ThemeDataView(APIView):
    def get(self,request):
        theme_id = request.GET.get('order_col', False)
        if theme_id:
            theme_id = list(theme_id.split(','))
            column_data = Column.objects.filter(id__in=theme_id).values()
            data = column_clear_data(column_data)
            return Response(data)
        return Response({})

